home *** CD-ROM | disk | FTP | other *** search
- /* _OPEN.C --- p. 643 */
- #include <stdio.h>
- #include <fcntl.h>
- #include <dos.h>
- #include <io.h>
- main()
- {
- char fname[40], *p_fname;
- int filehandle;
- printf("Enter name of file to open using _open: ");
- p_fname = gets(fname);
- /* Open the file in "DENY ALL" mode and for reading
- * only */
- if((filehandle = _open(p_fname, O_DENYALL | O_RDONLY)) == -1)
- {
- printf("Error opening file: %s\n", fname);
- exit(0);
- }
- printf("File %s opened.\n", fname);
- /* Now close file */
- if(_close(filehandle) == -1)
- {
- printf("Error closing file with _close\n");
- exit(0);
- }
- printf("File %s closed.\n", fname);
- }